<template>
	<view class="page" :style="themeColor">
		<view class="flex benben-position-layout flex flex-wrap align-center cardAndSafe_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub cardAndSafe_fd0_0'>
				<view class='flex flex-wrap align-center'>
					<person></person>
				</view>
				<view class='flex flex-wrap align-stretch justify-center flex-sub'>
					<text class='cardAndSafe_fd0_0_c1_c0'>我的账户</text>
				</view>
				<view class='flex flex-wrap align-center cardAndSafe_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#6A0002"></u-loading>
			<view class="loading_text">加载中</view>
		</view>
		<!---账号与安全两列flex布局开始-->
		
		<template v-else>
			<view class="list">
				<view class="list_item" v-for="(item, index) in accountList" :key="index">
					<view class="item_top">
						<view class="item_top_1">{{item.cardname}}</view>
						<view class="item_top_2" v-if="!item.isSelect" @tap.stop="manage(index)">
							<text>管理</text>
						</view>
						<view class="item_top_2" @tap.stop="yichu(index)" v-else>
							<text>移除</text>
						</view>
					</view>
					<view class="item_bottom">
						{{item.account_id}}
					</view>
				</view>
			</view>
			
			<view class="noData" v-if="accountList.length == 0 && !isShow">
				<image src="/static/empty/no.png"></image>
			</view>
			
			<view class="add_btn" @tap.stop="addAccount">
				<text>新增账户</text>
			</view>
		</template>

		<u-popup v-model="show" mode="center" border-radius="16">
			<view class="add_popup">
				<view class="add_title">新增账户</view>
				<view class="add_tabs">
					<view class="add_tabs_item" @tap.stop="selectAcc(4)">
						<image v-if="acc_type == 4" :src='STATIC_URL+"1.png"' mode="aspectFill"></image>
						<image v-else :src='STATIC_URL+"51.png"' mode="aspectFill"></image>
						<text>欧洲银行账户</text>
					</view>
					<view class="add_tabs_item" @tap.stop="selectAcc(3)">
						<image v-if="acc_type == 3" :src='STATIC_URL+"1.png"' mode="aspectFill"></image>
						<image v-else :src='STATIC_URL+"51.png"' mode="aspectFill"></image>
						<text>中国银行账户</text>
					</view>
				</view>
				<view class="set_up">第一步</view>
				<view class="input_value">
					<view class="input_value_1">选择银行</view>
					<view class="input_value_2">
						<input placeholder="请输入" placeholder-style="color:#bfbfbf;font-size:26rpx;"
							v-model="yinhangname" type="text">
					</view>
				</view>
				<view class="set_up">第二步</view>
				<view class="input_value">
					<view class="input_value_1">开户姓名</view>
					<view class="input_value_2">
						<input placeholder="请输入" placeholder-style="color:#bfbfbf;font-size:26rpx;" v-model="bankName"
							type="text">
					</view>
				</view>
				<view class="input_value">
					<view class="input_value_1">银行账号</view>
					<view class="input_value_2">
						<input placeholder="请输入" placeholder-style="color:#bfbfbf;font-size:26rpx;" v-model="name"
							type="text">
					</view>
				</view>
				<view class="input_value">
					<view class="input_value_1">开户网点</view>
					<view class="input_value_2">
						<input placeholder="请输入" placeholder-style="color:#bfbfbf;font-size:26rpx;"
							v-model="bankCardNumber" type="text">
					</view>
				</view>
				<view class="add_bom">
					<view class="add_bom_1" @tap.stop="close">取消</view>
					<view class="add_bom_2"></view>
					<view class="add_bom_3" @tap.stop="getSubmit">提交</view>
				</view>
			</view>
		</u-popup>
		
		
		<benben-popup v-model="unbindshow" :mask="true" mode='center'>
			<view class="flex flex-direction align-stretch benben-flex-layout vip_flex_311">
				<view class='flex align-center justify-center'>
					<text class='vip_fd3_0_c0'>输入支付密码</text>
				</view>
				<view class='flex align-center justify-center vip_fd3_1'>
					<benben-digital-password :box-num='6' mode='password' v-model='PayPwd'
						class-name="flex flex align-center justify-center vip_fd3_1_c0">
						<!--  @confirm="checkCodeFunc()"-->
						<template #default="{ content, active, index }">
							<view :key="index" v-if="active"
								class="flex align-center justify-center active-digital-password vip_flex_password_active_fd3_1_c0">
								{{ content }}
							</view>
							<view :key="index" v-else
								class="flex align-center justify-center vip_flex_password_noActive_fd3_1_c0">
								{{ content }}
							</view>
						</template>
					</benben-digital-password>
				</view>
				<view class='flex align-center justify-between'>
					<button class='vip_fd3_2_c0' @tap.stop="closePsd">取消</button>
					<button class='vip_fd3_2_c1' @tap.stop="confirmUnbind()">确认</button>
					<!-- @tap.stop="goumai()" -->
				</view>
			</view>
		</benben-popup>
		
	</view>
</template>
<script>
	import back from "@/components/back/index.vue"
	import person from "@/components/person/index.vue"
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {
			back,
			person
		},


		data() {
			return {
				unbindshow: false,
				show: false,
				yinhangname: "",
				bankName: "",
				name: "",
				bankCardNumber: "",
				acc_type: 4,
				timerId: null,
				isShow: true,
				accountList: [],
				account_id: "",
				PayPwd: ""
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			this.getAccountData();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 提现绑定账号列表  post659bc192930af
			getAccountData() {
				this.$api.post(global.apiUrls.post659bc192930af, {
					
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 1) {
						this.accountList = res.data.data;
						if (this.accountList.length > 0) {
							this.accountList.forEach((v, k) => {
								v.isSelect = false;
							})
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			
			selectAcc(type) {
				this.acc_type = type;
				this.yinhangname = "";
				this.bankName = "";
				this.name = "";
				this.bankCardNumber = "";
			},
			// 取消
			close() {
				this.yinhangname = "";
				this.bankName = "";
				this.name = "";
				this.bankCardNumber = "";
				this.show = false;
			},
			addAccount() {
				this.show = true;
				if (this.accountList.length > 0) {
					this.accountList.forEach((v, k) => {
						v.isSelect = false;
					})
				}
			},
			manage(index) {
				if (this.accountList.length > 0) {
					this.accountList.forEach((v, k) => {
						v.isSelect = false;
					})
					this.accountList[index].isSelect = true;	
				}
				this.$forceUpdate();
			},
			yichu(index) {
				this.account_id = this.accountList[index].id;
				this.unbindshow = true;
			},
			// 解绑账号  a647d81f92e8a5
			confirmUnbind() {
				if (!this.PayPwd) {
					this.$message.info('请输入支付密码');
					return;
				}
				this.unbindshow = false;
				this.$api.post(global.apiUrls.a647d81f92e8a5, {
					account_id: this.account_id,
					password: this.PayPwd
				}).then(res => {
					this.PayPwd = "";
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.getAccountData();
					}
				})
			},
			closePsd() {
				this.unbindshow = false;
			},
			
			// 提交
			//绑定欧洲银行
			async getSubmit() {
				if (this.timerId) {
					clearTimeout(this.timerId)
				}
				if (!validate(this.yinhangname, 'require')) {
					this.$message.info('请输入银行卡名称');
					return false;
				}
				if (!validate(this.bankName, 'require')) {
					this.$message.info('请输入开户姓名');
					return false;
				}
				if (!validate(this.name, 'require')) {
					this.$message.info('请输入银行账号');
					return false;
				}
				
				if (!validate(this.bankCardNumber, 'require')) {
					this.$message.info('请输入银行开户网点');
					return false;
				}
				this.show = false;
				this.timerId = setTimeout(async () => {
					let res = await this.$api.post(global.apiUrls.bangdingzhanghao, {
						account_type: this.acc_type,
						cardname: this.yinhangname,
						account_id: this.name,
						true_name: this.bankName,
						cardbank: this.bankCardNumber
					})
					if (res.data.code != 1) {
						this.$message.info(res.data.msg)
						return
					}
					this.getAccountData();
					this.$message.info(res.data.msg);
					this.yinhangname = "";
					this.bankName = "";
					this.name = "";
					this.bankCardNumber = "";
				}, 800)
			},
		}
	};
</script>
<style lang="scss" scoped>
	.add_popup {
		width: 640rpx;
		// height: 850rpx;
		background: #FFFFFF;
		border-radius: 16rpx;

		// padding:0 50rpx;
		.add_title {
			font-size: 34rpx;
			font-weight: 500;
			text-align: center;
			padding: 38rpx 0 28rpx;
		}

		.add_tabs {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 50rpx;

			.add_tabs_item {
				display: flex;
				align-items: center;
				font-size: 30rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 16rpx;
				}
			}
		}

		.set_up {
			font-size: 28rpx;
			color: #333;
			margin-top: 30rpx;
			padding: 0 50rpx;
		}

		.input_value {
			padding: 0 50rpx;
			display: flex;
			align-items: center;
			margin-top: 22rpx;

			.input_value_1 {
				font-size: 28rpx;
				margin-right: 33rpx;
			}

			.input_value_2 {
				width: 394rpx;
				height: 64rpx;
				background: #F8F8F8;
				border-radius: 8rpx;

				input {
					width: 100%;
					height: 100%;
					padding: 0 24rpx;
					font-size: 26rpx;
				}
			}
		}

		.add_bom {
			display: flex;
			height: 93rpx;
			margin-top: 60rpx;
			border-top: 1px solid #eee;

			.add_bom_1 {
				width: 319rpx;
				height: 100%;
				text-align: center;
				line-height: 93rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: #999;
			}

			.add_bom_2 {
				width: 1px;
				height: 100%;
				background: #eee;
			}

			.add_bom_3 {
				width: 319rpx;
				height: 100%;
				text-align: center;
				line-height: 93rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: #6A0002;
			}
		}
	}

	.list {
		padding: 0 32rpx;

		.list_item {
			margin: 24rpx 0 0;
			width: 686rpx;
			height: 280rpx;
			background: url(/static/images/117.png) no-repeat;
			background-size: 100% 100%;
			padding: 32rpx 40rpx;

			.item_top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.item_top_1 {
					font-size: 32rpx;
					font-weight: 500;
					color: #fff;
				}

				.item_top_2 {
					font-size: 24rpx;
					font-weight: 400;
					color: #fff;
				}
			}

			.item_bottom {
				font-size: 48rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				margin: 72rpx 0 0 96rpx;
			}
		}
	}

	.add_btn {
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
		background: #6A0002;
		border-radius: 44rpx;
		font-size: 32rpx;
		color: #fff;
		text-align: center;
		position: fixed;
		left: 32rpx;
		bottom: 64rpx;
	}
	
	
	.vip_flex_311 {
		background: #fff;
		width: 540rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 32rpx 24rpx 24rpx 24rpx;
	}
	
	.vip_fd3_0_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #000000;
	}
	
	.vip_fd3_1 {
		margin: 24rpx 0rpx 40rpx 0rpx;
	}
	
	::v-deep .vip_fd3_1_c0 {
		width: 750rpx;
		height: 160rpx;
	}
	
	.vip_flex_password_noActive_fd3_1_c0 {
		border: 1px solid #ccc;
		width: 68rpx;
		height: 68rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
	}
	
	.vip_fd3_2_c0 {
		background: #F2F2F2;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		font-size: 28rpx;
		color: #333;
		width: 234rpx;
		height: 72rpx;
		font-weight: 500;
		line-height: 72rpx;
	}
	
	.vip_fd3_2_c1 {
		background: #6a0002;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		font-size: 28rpx;
		color: #e6e6e6;
		width: 234rpx;
		height: 72rpx;
		font-weight: 500;
		line-height: 72rpx;
	}
	
	.vip_flex_password_active_fd3_1_c0 {
		border: 1px solid #409EFF;
		width: 68rpx;
		height: 68rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
	}
	
	

	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}

	.cardAndSafe_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.cardAndSafe_fd0_0_c2 {
		width: 40rpx;
		height: 40rpx;
	}

	.cardAndSafe_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.cardAndSafe_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.cardAndSafe_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.cardAndSafe_flex_1 {
		background: #fff;
		font-size: 32rpx;
		background-size: 100% auto !important;
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.cardAndSafe_fd1_3 {
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.cardAndSafe_fd1_0_c1 {
		font-size: 26rpx;
		color: rgba(191, 191, 191, 1);
		font-weight: 400;
	}

	.cardAndSafe_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.cardAndSafe_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.cardAndSafe_flex_2 {
		height: 88rpx;
		position: fixed;
		bottom: 64rpx;
		left: 30rpx;
	}

	.cardAndSafe_fd2_0 {
		background: #6A0002;
		border-radius: 44rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #fff;
		width: 690rpx;
		height: 88rpx;
		line-height: 88rpx;
	}
</style>